<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试二维码生成器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .container {
            text-align: center;
        }
        .form-group {
            margin: 20px 0;
            text-align: left;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input, select, textarea {
            width: 100%;
            padding: 8px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            background: #667eea;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            margin: 10px;
        }
        button:hover {
            background: #5a6fd8;
        }
        .qr-container {
            margin: 20px 0;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
            background: #f9f9f9;
        }
        #qrcode {
            margin: 20px auto;
        }
        .preset-buttons {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            justify-content: center;
            margin: 20px 0;
        }
        .preset-btn {
            background: #28a745;
            font-size: 14px;
            padding: 8px 16px;
        }
        .preset-btn:hover {
            background: #218838;
        }
        .instructions {
            text-align: left;
            background: #e7f3ff;
            padding: 15px;
            border-radius: 5px;
            margin: 20px 0;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>测试二维码生成器</h1>
        <p>生成包含MAC地址的二维码，用于测试扫描功能</p>
        
        <div class="instructions">
            <h3>使用说明：</h3>
            <ol>
                <li>选择预设格式或自定义内容</li>
                <li>点击"生成二维码"按钮</li>
                <li>使用手机扫描生成的二维码</li>
                <li>在软件正版化查询页面测试扫描功能</li>
            </ol>
        </div>
        
        <div class="preset-buttons">
            <button class="preset-btn" onclick="setPreset('direct')">直接MAC地址</button>
            <button class="preset-btn" onclick="setPreset('json')">JSON格式</button>
            <button class="preset-btn" onclick="setPreset('url')">URL参数</button>
            <button class="preset-btn" onclick="setPreset('custom')">自定义</button>
        </div>
        
        <div class="form-group">
            <label for="format">数据格式：</label>
            <select id="format" onchange="updateFormat()">
                <option value="direct">直接MAC地址</option>
                <option value="json">JSON格式</option>
                <option value="url">URL参数</option>
                <option value="custom">自定义内容</option>
            </select>
        </div>
        
        <div class="form-group">
            <label for="macAddress">MAC地址：</label>
            <input type="text" id="macAddress" value="00:11:22:33:44:55" placeholder="例如：00:11:22:33:44:55">
        </div>
        
        <div class="form-group">
            <label for="content">二维码内容：</label>
            <textarea id="content" rows="4" placeholder="二维码内容将根据选择的格式自动生成"></textarea>
        </div>
        
        <button onclick="generateQR()">生成二维码</button>
        <button onclick="clearQR()">清除</button>
        
        <div class="qr-container">
            <div id="qrcode"></div>
            <p id="qrInfo"></p>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.3/build/qrcode.min.js"></script>
    <script>
        function updateFormat() {
            const format = document.getElementById('format').value;
            const macAddress = document.getElementById('macAddress').value || '00:11:22:33:44:55';
            let content = '';
            
            switch(format) {
                case 'direct':
                    content = macAddress;
                    break;
                case 'json':
                    content = JSON.stringify({ mac: macAddress, device: 'Test Device' });
                    break;
                case 'url':
                    content = `http://example.com/device?mac=${macAddress}&type=computer`;
                    break;
                case 'custom':
                    content = '请输入自定义内容';
                    break;
            }
            
            document.getElementById('content').value = content;
        }
        
        function setPreset(type) {
            document.getElementById('format').value = type;
            updateFormat();
        }
        
        function generateQR() {
            const content = document.getElementById('content').value;
            if (!content.trim()) {
                alert('请输入二维码内容');
                return;
            }
            
            const qrContainer = document.getElementById('qrcode');
            qrContainer.innerHTML = '';
            
            QRCode.toCanvas(content, {
                width: 256,
                height: 256,
                margin: 2,
                color: {
                    dark: '#000000',
                    light: '#FFFFFF'
                }
            }, function (error, canvas) {
                if (error) {
                    console.error('生成二维码失败:', error);
                    document.getElementById('qrInfo').textContent = '生成失败：' + error.message;
                } else {
                    qrContainer.appendChild(canvas);
                    document.getElementById('qrInfo').innerHTML = 
                        `<strong>二维码内容：</strong><br>${content}<br><br>` +
                        `<strong>内容长度：</strong>${content.length} 字符<br>` +
                        `<strong>生成时间：</strong>${new Date().toLocaleString()}`;
                }
            });
        }
        
        function clearQR() {
            document.getElementById('qrcode').innerHTML = '';
            document.getElementById('qrInfo').textContent = '';
        }
        
        // 监听MAC地址输入变化
        document.getElementById('macAddress').addEventListener('input', function() {
            if (document.getElementById('format').value !== 'custom') {
                updateFormat();
            }
        });
        
        // 页面加载时初始化
        window.addEventListener('load', function() {
            updateFormat();
            generateQR();
        });
    </script>
</body>
</html>